package src.LLVM.control;

import src.LLVM.IR;

public class IcmpIR implements IR {
    private final String resReg;
    private final String opt;
    private final String left;
    private final String right;
    public IcmpIR(String resReg, String left, String opt, String right){
        this.left = left;
        this.right = right;
        switch (opt) {
            case "==" -> opt = "eq";
            case "!=" -> opt = "ne";
            case ">" -> opt = "sgt";
            case ">=" -> opt = "sge";
            case "<" -> opt = "slt";
            case "<=" -> opt = "sle";
            case "&&" -> opt = "and";
            case "||" -> opt = "or";
        }
        this.opt = opt;
        this.resReg = resReg;
    }

    @Override
    public String toString() {
        //    %v39 = icmp ne i32 0, %v38
        if(left.length() == 0 || right.length() == 0){
            System.out.println("error Icmp");
            throw new RuntimeException();
        }
        return "\t" + resReg + " = icmp " + opt + " i32 " + left + ", " + right;
    }
}
